var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
require('./database/content.js')
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var followRouter = require('./routes/follow')
const { createProxyMiddleware } = require('http-proxy-middleware');
var app = express();

app.use('/node', createProxyMiddleware({
    target: 'http://localhost:3001', //期望访问的目标服务器
    pathRewrite: {
        '^/node': ''
    },
    changeOrigin: true
}));

app.use('/hehe', createProxyMiddleware({
    target: "https://basic-service.baidu.com", //期望访问的目标服务器
    pathRewrite: {
        "^/hehe": "",
    },
    changeOrigin: true
}));

app.use('/home', createProxyMiddleware({
    target: "https://jia.baidu.com", //期望访问的目标服务器
    pathRewrite: {
        "^/home": "",
    },
    changeOrigin: true
}));
app.listen(3000);
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/follow', followRouter);

module.exports = app;